import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

class TextDemoPage extends StatefulWidget {
  const TextDemoPage({super.key});

  @override
  State<TextDemoPage> createState() => _TextDemoPageState();
}

class _TextDemoPageState extends State<TextDemoPage> {
  void refresh() {
    setState(() {});
  }

  late var nameController;

  @override
  void initState() {
    super.initState();
    nameController =
        TextEditingController()..addListener(() {
          refresh();
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("text 组件使用")),
      body: Container(
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            TextField(controller: nameController),
            Text("例子:文本组件显示" + nameController.text).marginOnly(top: 10),
            Container(
              width: 200,
              child: LayoutBuilder(
                builder: (context, constract) {
                  print(constract.maxWidth);
                  return Container(
                    height: constract.maxWidth*9/16,
                    color: Colors.blue,
                    child: Center(child: Text('16:9 比例')),
                  );
                },
              ),
            ),

            Text(
              "例子:我是文本组件",
              style: TextStyle(fontStyle: FontStyle.italic),
            ).marginOnly(top: 10),
            Text(
              "例子:我是文本组件2",
              style: TextStyle(fontWeight: FontWeight.bold),
            ).marginOnly(top: 10, bottom: 10),
            Text.rich(
              TextSpan(
                children: [
                  TextSpan(text: "例子:"),
                  TextSpan(
                    text: "我是文本组件3",
                    style: TextStyle(color: Colors.red),
                    recognizer:
                        TapGestureRecognizer()
                          ..onTap = () {
                            Fluttertoast.showToast(msg: "点击跳转");
                          },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
